package cn.dxs.adt.utils;

import android.app.Notification;
import android.app.PendingIntent;
import android.view.accessibility.AccessibilityEvent;

import java.util.List;

/**
 * 辅助服务工具类
 */
public class AsUtil {

    /**
     * 处理通知栏信息
     * 如果是微信红包的提示信息,则模拟点击
     *
     * @param event
     */
    public static void handleNotification(AccessibilityEvent event) {
        List<CharSequence> texts = event.getText();
        if (texts.isEmpty()) {
            return;
        }
        for (CharSequence text : texts) {
            String content = text.toString();
            //如果微信红包的提示信息,则模拟点击进入相应的聊天窗口
            if (content.contains("[微信红包]")) {
                if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
                    Notification notification = (Notification) event.getParcelableData();
                    PendingIntent pendingIntent = notification.contentIntent;
                    try {
                        pendingIntent.send();
                    } catch (PendingIntent.CanceledException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    /**
     * 处理窗口状态改变
     * @param event
     */
    public static void handleWindowStateChanged(AccessibilityEvent event) {
        if (event.getPackageName() != null && event.getClassName() != null) {
            if(event.getClassName().toString().equals("com.alipay.mobile.nebulax.integration.mpaas.activity.NebulaActivity$Main")){
//                isType("支付宝账单界面",event);
            }else if (event.getClassName().toString().equals("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI")){
//                isType("微信红包详情界面",event);            //判断进入微信红包详情界面
            }else if(event.getClassName().toString().equals("com.tencent.mm.plugin.webview.ui.tools.WebViewUI")){
//                isType("微信账单详情界面",event);               //判断进入微信账单列表界面
            }else if(event.getClassName().toString().equals("com.unionpay.cordova.UPActivityWeb")){
//                isType("云闪付账单详情界面",event);     //判断进入云闪付账单详情列表界面
            }else if(event.getClassName().toString().equals("cn.dxs.adt.MainActivity")){
            }  else {

            }
        }
    }

}
